package com.genersoft.iot.vmp.storager.dao;

import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 用于存储业务报警
 */
@Mapper
@Repository
public interface DeviceAlarmMapper {

    @Insert("INSERT INTO alarm (" +
                "sn," +
                "deviceId," +
                "channelId," +
                "alarmPriority," +
                "alarmMethod," +
                "alarmTime," +
                "alarmDescription," +
                "longitude," +
                "latitude," +
                "alarmType," +
                "eventType"+
            ") VALUES (" +
                "#{sn}," +
                "#{deviceId}," +
                "#{channelId}," +
                "#{alarmPriority}," +
                "#{alarmMethod}," +
                "#{alarmTime}," +
                "#{alarmDescription}," +
                "#{longitude}," +
                "#{latitude}," +
                "#{alarmType}," +
                "#{eventType}" +
            ")")
    int add(DeviceAlarm alarm);

    @Select("SELECT * FROM alarm order by id desc")
    List<DeviceAlarm> queryAlarms();

    @Select("SELECT * FROM alarm where deviceId = #{deviceId} order by id desc")
    List<DeviceAlarm> queryAlarmsByDeviceId(String deviceId);
}
